Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

locale-code

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

locale-code

locale code based on iso-639-1 and iso-3166-1

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.6K
increased by14.13%
Maintainers
1
Weekly downloads
 
Created
Source

locale-code

NPM Version Build Status Download Count

Simple interface for ISO-639-1 language codes and ISO-3166-1-alpha-2 country codes.

Install

npm install locale-code

Methods

getLanguageCode(code)

  • @param code {string}
  • @return {string}

Lookup language code from locale code

getLanguageName(code)

  • @param code {string}
  • @return {string}

Lookup language english name by code

getLanguageNativeName(code)

  • @param code {string}
  • @return {string}

Lookup language native name by code

validateLanguageCode(code)

  • @param code {string}
  • @return {boolean}

Check whether the given code is in the list of ISO-639-1

getLanguages(codes)

  • @param codes {array}
  • @return {array}

Get the array of the language objects by the given codes

getCountryCode(code)

  • @param code {string}
  • @return {string}

Lookup country code from locale code

getCountryName(code)

  • @param code {string}
  • @return {string}

Lookup country name by code

validateCountryCode(code)

  • @param code {string}
  • @return {boolean}

Check whether the given code is in the list of ISO-3166-1-alpha-2

validate(code)

  • @param code {string}
  • @return {boolean}

Check whether the given code is in the list of ISO-639-1 and ISO-3166-1-alpha-2

Usage

var  LocaleCode = require('locale-code')

console.log(LocaleCode.getLanguageCode('en-US')); // 'en'

console.log(LocaleCode.getLanguageName('zh-CN')); // 'Chinese'

console.log(LocaleCode.getLanguageNativeName('zh-CN')); // '中文'

console.log(LocaleCode.getLanguageZhName('es-ES')); // '西班牙语'

console.log(LocaleCode.validateLanguageCode('en-US')); // true

console.log(LocaleCode.validateLanguageCode('bb-US')); // false

console.log(LocaleCode.getLanguages(['en-US','zh-CN'])); 
// [{code:'en-US', name:'English', nativeName:'English', zhName:'英语'}, {code:'zh-CN', name:'Chinese', nativeName:'中文', zhName:'中文'}]


console.log(LocaleCode.getCountryCode('en-US')); // 'US'

console.log(LocaleCode.getCountryName('en-US')); // 'United States'

console.log(LocaleCode.validateCountryCode('en-US')); // true

console.log(LocaleCode.validateCountryCode('en-ZZ')); // false

console.log(LocaleCode.validate('en-US')); // true

console.log(LocaleCode.validate('en_US')); // false

console.log(LocaleCode.validate('bb-XX')); // false

Keywords

FAQs

Package last updated on 11 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc